﻿
using System.Collections.Generic;
using Microsoft.Phone.UserData;
namespace DIS.WindowsPhone.Toolkit.Controls
{
    /// <summary>
    /// Represents a class used to group contacts by their first letter
    /// </summary>
    public class GroupedContacts : IEnumerable<Contact>
    {
        public GroupedContacts(string name, IEnumerable<Contact> items, bool isEnabled)
        {
            this.Title = name;
            this.Contacts = new List<Contact>(items);
            this.IsEnabled = isEnabled;
        }

        public override bool Equals(object obj)
        {
            GroupedContacts that = obj as GroupedContacts;

            return (that != null) && (this.Title.Equals(that.Title));
        }

        public override int GetHashCode()
        {
            return Title.GetHashCode() + Contacts.GetHashCode();
        }

        /// <summary>
        /// Gets the title of the grouped contacts
        /// </summary>
        public string Title
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the list of contacts that are grouped together
        /// </summary>
        public IList<Contact> Contacts
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets whether this group is enabled or not
        /// </summary>
        public bool IsEnabled { get; private set; }

        #region IEnumerable<Contact> Members

        public IEnumerator<Contact> GetEnumerator()
        {
            return this.Contacts.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.Contacts.GetEnumerator();
        }

        #endregion
    }
}
